<?php
namespace Admin\Controller;

class NeedController extends AdminController {

	public function index(){
		$obj = M('Needs');
		$count = $obj->where($map)->count();
		import("Common.ORG.Page");
		$page = new \Page($count, 20);
		$show = $page->show();
		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->display();
	}

	//查看
	public function view(){
		$id=I("id");
		if(empty($id)){
			$this->error(L("_no_selected"));
		}else{
			$map['id']=$id;
			$list=M("Needs")->where($map)->find();
			$this->assign("list",$list);
			$this->display();
		}
	}

	//单个删除
	public function del(){
		$id=I("id");
		if(empty($id)){
			$this->error(L("_no_selected"));
		}else{
			$map['id']=$id;
			if(M("Needs")->where($map)->delete()){
				$this->success(L('_action_success'));
			}else{
				$this->error(L('_action_fail'));
			}
		}
	}

	public function delall(){	
		$id=I('post.selectedids');
		if($id==''){
			$state = L("_no_selected");
		}else{
			foreach ($id as $v) {
				$obj = M('Needs');
				$where['id'] = $v;
				$obj->where($where)->delete();
			}
			$state = 'SUCCESS';
	        $message = L('_action_success');
	        $url = U('Need/index');
		}
		echo $this->echo_json_str($state,$message,$url);
    }
}
?>